SAS字符型函数 您所在的位置:网站首页 sas strip函数 SAS字符型函数

SAS字符型函数

#SAS字符型函数| 来源: 网络整理| 查看: 265

528866wmYSJ*

```sql data compress_1; x1=" 1 2 a 3"; x2="Abacabbad"; x3="134-7596-5241"; x4="123***14567"; y1=compress(x1," "); y2=compress(x2,"Ab");/*消除的是A 或b不是且的关系*/ y3=compress(x3,"0123456789","k"); /*消除除了数字外的所有其它字符*/ y4=compress(x4,"0123456789","k"); run; 在这里插入代码片`在这里插入代码片` ```sql data compress_1; x1=" 1 2 a 3"; x2="Abacabbad"; x3="134-7596-5241"; x4="123***14567"; y1=compress(x1," "); y2=compress(x2,"Ab");/*消除的是A 或b不是且的关系*/ y3=compress(x3,"0123456789","k"); y4=compress(x4,"0123456789","k"); y5=compress(x1);/*什么都不写,默认是清楚空格*/ run; data compress_mob; length Mob_Phe$ 14; input Mob_Phe$ @@; Cards; 13915625877 013145672561 134-7596-5241 1364524124 01045125421 ; run; /*要消除不是数字的其它字符*/ data mob1; set compress_mob; if length(compress(Mob_Phe,"0123456789","k"))=11 then do; mob_phone=substr(compress(Mob_Phe,"0123456789","k"),1,11); if substr(compress(Mob_Phe),1,3) in("130","131","132","133","150","151","152","153") then do; flag="联通";output;END; else if substr(compress(Mob_Phe),1,3) in("134","135","136","137","138","139", "154","155","156","157","158","159") then do; flag="移动";output;END; end; else if length(compress(Mob_Phe,"0123456789","k"))=12 and substr(compress(Mob_Phe),1,1)="0" then do; mob_phone=substr(compress(Mob_Phe,"0123456789","k"),2,11); if substr(compress(Mob_Phe),2,3) in("130","131","132","133","150","151","152","153") then do; flag="联通";output;END; else if substr(compress(Mob_Phe),2,3) in("134","135","136","137","138","139", "154","155","156","157","158","159") then do; flag="移动";output;END; end; run;

在这里插入图片描述

在这里插入图片描述 if then 是满足if条件并执行后面一个语句 if then do…end;满足if语句并执行do和end之间的所有语句,通常用于多个语句的时候可以用do end 另外,substr(str,3,11)指的是从第3位开始取,共取11个,且没有第0位,都是第一个

/*put函数,把数值型和字符型变量转为字符型变量,put(source,format),format是输出的格式*/ /*sas中数据类型只有两种,一种数值型一种字符型*/ /*"01Jan2007"D这实际是数值型的变量,可以参与数值变化,如何转化为字符型*/ data test; X="01Jan2007"D; y=put(X,yymmdd10.); Z=compress(y,"-"); run;

发现对X没有规定格式,输出的是数字 在这里插入图片描述

data test; X="01Jan2007"D; format x yymmdd10.;规定了x的输出格式,但仍然是数值型的 y=put(X,yymmdd10.); Z=compress(y,"-"); run;

在这里插入图片描述

/*substr(),从第几位开始取,共取几位*/ data test3; x="abcd e"; y=substr(x,2);*从第二位开始取直到结束; y2=substr(x,2,1); z=substr(x,length(x)-3,4);/*从后面开始取,取四位,那么length()-3*/ /*就是取几位,那么length()减去取几位再减一*/ put x=; put y=; put y2=; put z=; run;

x=abcd e y=bcd e y2=b z=cd e

/*tranwrd替代字符,tranwrd(str,需要替代的字符,替换成哪个字符)*/ data test4; x="abcdaba"; x1=compress(x,"ab"); y=tranwrd(x,"ab","k"); z=tranwrd(x,"ab",""); lz=length(z); z1=tranwrd(x,"ab"," "); lz1=length(z1); m=compress(z); m1=compress(z1); put x=; put x1=; put y=; put z=; put lz=; put z1=; put lz1=; put m=; put m1=; run;

x=abcdaba x1=cd y=kcdka z=cd a lz=5 z1=cd a lz1=5 m=cda m1=cda



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有